package internationalenergytradingplatform.controller.AdministratorsController;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import internationalenergytradingplatform.VO.OrderPageQueryVO;
import internationalenergytradingplatform.VO.TransporterPageQueryVO;
import internationalenergytradingplatform.dao.TransporterAccountMapper;
import internationalenergytradingplatform.dao.TransporterMapper;
import internationalenergytradingplatform.dto.OrderPageQueryDTO;
import internationalenergytradingplatform.dto.TransporterPageQueryDTO;
import internationalenergytradingplatform.pojo.TransporterAccount;
import internationalenergytradingplatform.result.PageResult;
import internationalenergytradingplatform.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/administrator-transporter")
public class AdministratorTransporterController {

    @Autowired
    TransporterMapper transporterMapper;

    @Autowired
    TransporterAccountMapper transporterAccountMapper;

    @GetMapping("/paginationQuery")
    public Result<PageResult> adminPagingToQueryAllOrder(TransporterPageQueryDTO transporterPageQueryDTO){

        PageHelper.startPage(transporterPageQueryDTO.getPage(), transporterPageQueryDTO.getPageSize());
        Page<TransporterPageQueryVO> page = transporterMapper.transporterPageQueryAdmin(transporterPageQueryDTO);
        long total = page.getTotal();
        List<TransporterPageQueryVO> records = page.getResult();
        log.info("管理员分页查询结果：{}", records);
        PageResult pageResult = new PageResult(total, records);
        return Result.success(pageResult);
    }

    @PutMapping("/updateTransporterAccountState")
    public Result<String> updateTransporterAccountState(String tele, Integer state) {
        int updatedCount = transporterAccountMapper.updateTransporterAccountState(tele, state);
        if (updatedCount > 0) {
            return Result.success("运输商状态更新成功");
        } else {
            return Result.error("运输商状态更新失败");
        }
    }

}
